<template>
  <div class="app-container flex-col minH">
    <div class="topline w100p bgwhite pt20 pb10 radius10 pl10 pr20 justify-between">
      <div>
        <el-input v-model="uid" style="width: 280px" placeholder="搜尋評論用戶ID..." :prefix-icon="Search" class="search mr10 mb10" />
        <el-input v-model="touid" style="width: 280px" placeholder="搜尋被評論用戶ID..." :prefix-icon="Search" class="search mr10 mb10" />
        <el-input v-model="star_level" style="width: 280px" placeholder="搜尋星級..." :prefix-icon="Search" class="search mr10 mb10" />



      </div>
      <div class="noshrink mb10">
        <el-button class="btn2" @click="search()">查詢</el-button>
        <el-button class="btn1" @click="reset()">重置</el-button>
      </div>
    </div>
    <!-- <div class="bgblueg ptb20 radius10 w100p mt15 pl10 bold clr3c4">
      打賞總金額：933078.30元

    </div> -->
    <div class="mt15 radius10 hidden pb15 flex1 bgwhite  flex-col w100p">
      <div class="flex1 w100p ">
        <el-table :data="tableData" style="width: 100%" cell-class-name="tbcell" header-cell-class-name="hdcell" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" />
          <!-- <el-table-column prop="uid" label="評論用戶訊息" width="200" />
          <el-table-column prop="touid" label="被評論用戶訊息" width="200" /> -->
          <el-table-column prop="uid" label="評論用戶訊息" width="200">
            <template #default="scope">
              {{ scope.row.user.phone }}(ID:{{ scope.row.user.id }})
            </template>
          </el-table-column>
          <el-table-column prop="touser" label="被評論用戶訊息" min-width="200">
            <template #default="scope">
              {{ scope.row.touser.phone }}(ID:{{ scope.row.touser.id }})
            </template>
          </el-table-column>
          <el-table-column prop="comment" label="評價内容" />
          <el-table-column prop="star_level" label="星級" width="150" />

          <el-table-column prop="created_at" label="創建時間" sortable width="200" />
        </el-table>
      </div>
      <div class="plr20 justify-between w100p mt20">
        <div class="align-center">
          <el-button class="btn1" @click="toDel()">刪除</el-button>
        </div>
        <el-pagination v-model:current-page="currentPage" prev-text="上一頁" next-text="下一頁" :default-page-size="15" :small="small" :disabled="disabled" :background="true" layout="prev, pager, next, jumper" :total="total" @current-change="handleCurrentChange" />
      </div>

    </div>
  </div>
</template>

<script setup>
import { Search } from '@element-plus/icons-vue'
import { ref, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router';
import { commentList, commentDelete } from '@/api/order.js'
const route = useRoute()
onMounted(() => {
  if (route.query.uid) {
    touid.value = route.query.uid
    getCommentList()

  } else {
    getCommentList()

  }
})

// 评价列表
const getCommentList = () => {
  commentList({
    page: currentPage.value,
    star_level: star_level.value,
    uid: uid.value,
    touid: touid.value
  }).then((res) => {
    console.log('评价列表', res)
    tableData.value = res.data.data
    total.value = res.data.total
  })
}
const idStr = ref('')
const handleSelectionChange = (e) => {
  let idList = e.map((item, index) => { return item.id })
  idStr.value = idList.join(',')
  console.log(idList)
}
const uid = ref('')
const touid = ref('')
const star_level = ref('')


const tableData = ref([])
const currentPage = ref(1)
const total = ref(0)
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
  getCommentList()
}
const router = useRouter()
const toDel = () => {
  commentDelete({
    id: idStr.value
  }).then((res) => {
    console.log(res)
    getCommentList()
  })
}
const edit = (type) => {
  router.push({ path: 'signEdit' })
}
const search = () => {
  getCommentList()
}
const reset = () => {
  uid.value = ''
  touid.value = ''
  star_level.value = ''
  getCommentList()
}
</script>

<style lang="scss" scoped>
.search {
  overflow: hidden;
  border-radius: 10px !important;
  // padding: 5px 0px;
}
</style>
<style></style>
 